{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyo3demo\n",
    "import pyfunc\n",
    "import pyfunc_jit"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 乘除法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "154 ns ± 7.84 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 154 ns ± 7.84 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 10 -n 1000\n",
    "pyo3demo.two_multi_float(9999999.1,5555555.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "rs = _.average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "217 ns ± 4.95 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 217 ns ± 4.95 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 10 -n 1000\n",
    "pyfunc.two_multi_float_py(9999999.1,5555555.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "186 ns ± 38.9 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 186 ns ± 38.9 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 10 -n 1000\n",
    "pyo3demo.two_divi_float(999452.09871283,44.6642576)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "126 ns ± 27.2 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 126 ns ± 27.2 ns per loop (mean ± std. dev. of 10 runs, 1,000 loops each)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 10 -n 1000\n",
    "pyfunc.two_divi_float_py(999452.09871283,44.6642576)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 整数累加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.43 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 4.43 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 3\n",
    "pyfunc.int_sum_py(100000000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "297 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 297 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 3\n",
    "pyfunc_jit.int_sum_py(100000000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "460 ns ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 460 ns ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyo3demo.int_sum(100000000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = [i for i in range(1,5000)]\n",
    "y = [i for i in range(1000,7000)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "799 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 799 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyo3demo.matrix_multi(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.57 s ± 0 ns per loop (mean ± std. dev. of 1 run, 2 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 2.57 s ± 0 ns per loop (mean ± std. dev. of 1 run, 2 loops each)>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 2\n",
    "pyfunc.matrix_multi_py(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\AppData\\Roaming\\Python\\Python39\\site-packages\\numba\\core\\ir_utils.py:2147: NumbaPendingDeprecationWarning: \u001b[1m\n",
      "Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'x' of function 'matrix_multi_py'.\n",
      "\n",
      "For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types\n",
      "\u001b[1m\n",
      "File \"pyfunc_jit.py\", line 29:\u001b[0m\n",
      "\u001b[1m@numba.jit(nopython =True)\n",
      "\u001b[1mdef matrix_multi_py(x:list,y:list)->list:\n",
      "\u001b[0m\u001b[1m^\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))\n",
      "C:\\Users\\admin\\AppData\\Roaming\\Python\\Python39\\site-packages\\numba\\core\\ir_utils.py:2147: NumbaPendingDeprecationWarning: \u001b[1m\n",
      "Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'y' of function 'matrix_multi_py'.\n",
      "\n",
      "For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types\n",
      "\u001b[1m\n",
      "File \"pyfunc_jit.py\", line 29:\u001b[0m\n",
      "\u001b[1m@numba.jit(nopython =True)\n",
      "\u001b[1mdef matrix_multi_py(x:list,y:list)->list:\n",
      "\u001b[0m\u001b[1m^\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.09 s ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 1.09 s ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 5\n",
    "pyfunc_jit.matrix_multi_py(x,y)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 素数与孪生素数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 999999999999989"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.65 s ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 2.65 s ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyfunc.is_prime_py(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "364 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 364 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyo3demo.is_prime(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "242 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 242 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyfunc_jit.is_prime_py(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "451 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 451 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "pyo3demo.twin_primes(899990711311)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.25 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 3.25 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 3\n",
    "pyfunc.twin_primes_py(899990711311)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "352 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 2 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 352 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 2 loops each)>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 2\n",
    "pyfunc_jit.twin_primes_py(899990711311)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.07 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 5.07 s ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 3\n",
    "pyfunc.fibonacci_py(200000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.33 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 13 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 7.33 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 13 loops each)>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 13\n",
    "pyo3demo.fibonacci(200000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "54.1 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 54.1 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 3 loops each)>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 3\n",
    "pyfunc_jit.fibonacci_py(200000)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "513 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 513 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 5\n",
    "pyfunc.groupby(\"e:/jbnt.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "404 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 404 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 5 loops each)>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 5\n",
    "pyfunc_jit.groupby(\"e:/jbnt.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45.4 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<TimeitResult : 45.4 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 10 loops each)>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%timeit -o -r 1 -n 10\n",
    "x = pyo3demo.grouby(\"e:/jbnt.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shape: (11, 2)\n",
      "┌──────────┬───────────┐\n",
      "│ DLMC     ┆ TBMJ_sum  │\n",
      "│ ---      ┆ ---       │\n",
      "│ str      ┆ f64       │\n",
      "╞══════════╪═══════════╡\n",
      "│ 其他林地 ┆ 3.0170e8  │\n",
      "│ 旱地     ┆ 1.1411e10 │\n",
      "│ 其他草地 ┆ 7.8078e6  │\n",
      "│ 水田     ┆ 4.8245e7  │\n",
      "│ ...      ┆ ...       │\n",
      "│ 坑塘水面 ┆ 1.7052e8  │\n",
      "│ 采矿用地 ┆ 4.2813e6  │\n",
      "│ 水浇地   ┆ 1.3043e10 │\n",
      "│ 果园     ┆ 3.2097e8  │\n",
      "└──────────┴───────────┘\n"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ProDev",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "06b308fdbfd5979111721ebbf4de1ae2cbf405c7740d4ab5c57cb4c3e518bed6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
